<template>
    <!-- 
    <b-modal ref="my-modal" hide-footer title="Using Component Methods">
     <div class="d-block text-center">
       <h3>Hello From My Modal!</h3>
     </div>
     <b-button class="mt-3" variant="outline-danger" block @click="hideModal">Close Me</b-button>
     <b-button class="mt-2" variant="outline-warning" block @click="toggleModal">Toggle Me</b-button>
   </b-modal> 
    -->
    <!--
        body-class="modalStyle" 表示样式
        size="lg" 表示模态窗口大小 xl,lg,sm,full
        hide-footer 表示隐藏底部按钮
        hide-header 表示隐藏头部内容
        no-close-on-backdrop 表示鼠标点击背景不可关闭
        hide-header-close 表示隐藏头部关闭按钮
        centered 居中
        ok-title=“确定” 
        cancel-title=取消
        @ok="handleOk" 
        @cancel="handleCancel"
        scrollable 滚动条
        hide-backdrop 隐藏背景
        wrapClassName="ant-modal-cust-warp" 
        style="top:5%;height: 85%;overflow-y: hidden" 样式
        :modal-class="my-modal"
        dialog-class="modal-dialog"
        @hidden 关闭窗体触发事件
    -->
    <b-modal ref="my-modal" :title="title" scrollable  @hidden="onHidden" no-close-on-backdrop >
        <div class="d-block text-left">
            <div class="form-group m-form__group row">
                <label class="col-lg-2 col-form-label">业务Key</label>
                <div class="col-lg-6">
                    <input class="form-control" type="text" maxlength="100" v-model="businessKey" placeholder="请输入">
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-lg-2 col-form-label">指定节点</label>
                <div class="col-lg-6">
                    <input class="form-control" type="text" maxlength="100" v-model="activityId" placeholder="请输入">
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-lg-2 col-form-label">流程变量</label>
                <div class="col-lg-10">
                    <textarea class="form-control" cols="8" rows="6" v-model="variables" placeholder="请输入">
                    </textarea>
                </div>
               
            </div>
            <div class="form-group m-form__group row">
                <label class="col-lg-12 col-form-label">注：流程变量格式为json 如：{"number":5,"name":"xiaoshi"}</label>
            </div>
        </div>
        <template slot="modal-footer">
            <!--自定义按钮-->
            <button type="button" class="btn btn-light-danger font-weight-bold mr-2" block @click="hideModal">
                <i class="icon-xl fa fa-times"></i>取 消
            </button> 
            <button type="button" class="btn btn-light-success font-weight-bold mr-2" @click="startProcessInstanceByKey">
                <i class="icon-xl fas fa-save"></i> 保 存
            </button>
        </template>
    </b-modal>    
</template>
<script>
import apiUtil from "@/core/util/apiUtil.js";
import { handleNotify,handleAlert,handleConfirm,showWating,closeWating} from "@/core/util/jehcUtil.js";
export default {
    data(){
        return {
            title:"根据业务Key发起实例",
            id:"",
            businessKey:"",
            deploymentId:"",
            activityId:"",
            variables:null,
        }
    },
    components: {
    },
    watch: {
    },
    mounted() {        
       
    },
    methods: {        
        showModal(row) {
            this.businessKey=""
            this.$refs['my-modal'].show();
            if(null != row && undefined != row){
                this.id = row.id;
                this.title = "发起实例（原生态引擎）【"+row.deploymentName+"】";
                this.deploymentId = row.deploymentId

            }            
        },
        hideModal() {
            this.$refs['my-modal'].hide()
        },
        toggleModal() {
            // 当模态已隐藏时，我们传递要返回焦点的按钮的ID
            this.$refs['my-modal'].toggle('#toggle-btn')
        },
        onHidden(){//关闭窗体触发事件
            this.$emit("change",null);
        },
        startProcessInstanceByKey() {//发起业务实例（流程自带）
            if(this.businessKey === ""){
                handleAlert("请输入业务Key", "warning", 3)
                return;
            }
            // 保存前提示
            let params = {deploymentId:this.deploymentId,businessKey:this.businessKey,variables:JSON.parse(this.variables),activityId:this.activityId}
            // 操作前提示
            this.$bvModal.msgBoxConfirm("确定要发起实例？", {
                title: '提示',
                size: 'sm',
                buttonSize: 'sm',
                okVariant: 'success',
                okTitle: '确定',
                cancelTitle: '取消',
                headerClass: 'p-2 border-bottom-0',
                footerClass: 'p-2 border-top-0',
                hideHeaderClose: false,
                centered: true
            }).then(value => {
                if(value){
                    apiUtil.post(process.env.VUE_APP_BPM_API+"/original/startProcessInstance", params).then(({ data }) => {
                        if(data.success){
                            handleAlert("发起流程实例成功", "success", 3);
                            this.hideModal();//关闭窗体
                            this.$emit("change",data);//组件传值，即向父级模态框中传递值，采用change方式，目标刷新主列表使用
                        }else {
                            handleAlert("发起流程实例失败", "error", 3);
                        }            
                    });
                }                
            }).catch(err => {               
            })               
        },
   }
}
</script>